import Ember from 'ember';
import BaseBusiness from '../base-business';
import Pagination from '../pagination';
export default BaseBusiness.extend(Pagination, {
    dateService: Ember.inject.service("date-service"),
    queryParams: {
        id: {
            refreshModel: true
        },
        editMode: {
            refreshModel: true
        },
        flag: {
            refreshModel: true
        },
    },
    detailEdit: true,
    header_title: '编辑预警',
    model() {
        return {};
    },
    setupController(controller, model) {
        this._super(controller, model);
        var editMode = this.getCurrentController().get('editMode');
        var id = this.getCurrentController().get('id');
        var flag = this.getCurrentController().get('flag');
        if(flag == 'callFlag'){
          if (editMode == 'edit') {
              controller.set('detailEdit', false);
              controller.set("flagEdit", true);
              // this.store.findRecord('hbeaconwarning', id).then(function(warning) {
              //     controller.set('warning', warning);
              // });
              let warning = this.store.peekRecord('hbeaconwarning',id);
              controller.set('warning',warning);
          } else {
              controller.set("flagEdit", false);
              controller.set('detailEdit', true);
              controller.set('warning', this.store.createRecord('hbeaconwarning', {}));
          }
          controller.warningObs();
          this.store.query('customer', {
            filter:{
              '[customerStatus][typecode@$like]@$or1---1':'customerStatusIn',
              '[customerStatus][typecode@$like]@$or1---2':'customerStatusTry',
              'addRemark':'normal'
            }
          }).then(function(customerList) {
              customerList.forEach(function(customer) {
                  customer.set('namePinyin', customer.get("name"));
              });
              controller.set('customerList', customerList);
              controller.set('customerListFirst', customerList.get('firstObject'));
          });
          this.store.query("employee", {filter:{
            staffStatus:{'typecode@$not':Constants.staffStatusLeave}
          }}).then(function(staffList) {
              console.log("staffList is", staffList);
              staffList.forEach(function(staff) {
                  staff.set('operaterPinyin', staff.get("name"));
              });
              controller.set("staffList", staffList);
              controller.set('staffListFirst', staffList.get('firstObject'));
          });
        }else if(flag == 'sleepFlag'){
          let sleepmessage = this.store.peekRecord("sleepmessage",id);
          controller.set("sleepmessage", sleepmessage);
          let createDate = sleepmessage.get("createDate");
          let customerId = sleepmessage.get("customer.id");
          let curData = this.get("dateService").formatDate(createDate, "yyyy-MM-dd");
          let curTime = this.get("dateService").getFirstSecondStampOfDayString(curData);
          console.log("dataTime1:",curData,curTime);
          let endTimeBegin = curTime - 60 * 60 * 5;
          let endTimeEnd = curTime + 60 * 60 * 7;
          console.log("dataTime2:",endTimeBegin,endTimeEnd);
          var params = this.pagiParamsSet();
          var filter = {};
          var sort;
          filter = $.extend({}, filter, {caller:{id:customerId}});
          filter = $.extend({}, filter, {'reason@$or1---1':"深睡眠"});
          filter = $.extend({}, filter, {'reason@$or1---2':"浅睡眠"});
          filter = $.extend({}, filter, {'reason@$or1---3':"醒着"});
          filter = $.extend({}, filter, {
              'endTime@$gte': endTimeBegin
          }, {
              'endTime@$lte': endTimeEnd
          });
          params.filter = filter;
          sort = {
              '[endTime]': 'asc',
          };
          params.sort = sort;
          var warningList = this.findPaged('hbeaconwarning', params, function(warningList) {});
          controller.set("warningList", warningList);

        }
    }
});
